<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
 
// import Joomla modelitem library
jimport('joomla.application.component.modelitem');
 
/**
 * Main Model
 */
class WelliVermittlungModelArzt extends JModelItem
{
        /**
         * @var array messages
         */
        protected $item;
 
        /**
         * Returns a reference to the a Table object, always creating it.
         *
         * @param       type    The table type to instantiate
         * @param       string  A prefix for the table class name. Optional.
         * @param       array   Configuration array for model. Optional.
         * @return      JTable  A database object
         * @since       2.5
         */
        public function getTable($type = 'Arzt', $prefix = 'WelliVermittlungTable', $config = array()) 
        {
            JTable::addIncludePath(JPATH_COMPONENT.'/tables');
            return JTable::getInstance($type, $prefix, $config);
        }


        /**
         * Method to get the record form.
         *
         * @param       array   $data           Data for the form.
         * @param       boolean $loadData       True if the form is to load its own data (default case), false if not.
         * @return      mixed   A JForm object on success, false on failure
         * @since       2.5
         */
        public function getForm($data = array(), $loadData = true) 
        {
            // to test this use:
            // http://localhost/joomla3/index.php?option=com_wellivermittlung&view=arzt&layout=edit&id=3
            
            // Get the form.
            // This does only seem to work on admin side
            //$form = $this->loadForm('com_wellivermittlung.arzt', 'arzt', array('control' => 'jform', 'load_data' => $loadData));
            // So we have to build the path to the form ourselves. :( There surely is a better solution not found yet.
            $form = JForm::getInstance('frmarzt', JPATH_COMPONENT . '/models/forms/arzt.xml');
            
            if (empty($form)) 
            {
                    return false;
            }
            return $form;
        }

        /**
         * Get the message
         * @param  int    The corresponding id of the message to be retrieved
         * @return string The message to be displayed to the user
         */
        public function getItem($id = 0) 
        {
                if (!is_array($this->item))
                {
                        $this->item = array();
                }
 
                if (!isset($this->item[$id])) 
                {
                        //request the selected id
                        $jinput = JFactory::getApplication()->input;
                        $arztid = $jinput->get('id', 0, 'INT' );
 
                        // Get a TableHelloWorld instance
                        $table = $this->getTable();
 
                        // Load the message
                        $table->load($arztid);
 
                        // Assign the message
                        $this->item[$id] = Array(
                            'id' => $arztid,
                            'name' => $table->Name,
                            'name2' => $table->Name2);
                }
 
                return $this->item[$id];
        }


        
        // Method to build an SQL query to load the list data.
        // @return      string  An SQL query
        public function getListQuery()
        {
                // Create a new query object.           
                $db = JFactory::getDBO();
                $query = $db->getQuery(true);
                // Select some fields from the aerzte table
                $query
                    ->select('id,name,name2')
                    ->from('#__wellivermittlung_tieraerzte');
 
                return $query;
        }

    public function loadForm($param0, $param1, $param2) 
    {
        
    }

}


